<?php

// appel du header
require_once('./include/header.php');

$template->set_filenames(array(
        'body' => 'index/index.tpl',
));

if ( isset($_SESSION['user']) )
    header("Location: ./accueil.php");

if ( isset($_POST['valider']) ) {
        $login = $_POST['login'];
        $password = $_POST['password'];

        $template->assign_var('val_login', $login);
        $template->assign_var('val_password', $password);

        if ( $login != "" || $password != ""  ) {

            $res = $_user->login($login, $password);

            if ( $res == 0 ) {
                header("Location: ./accueil.php");
            }

            if ( $res == 1 ) {
                $template->assign_block_vars("error", array('ERROR' => 'Identifiant / Mot de passe erronés !'));
            }
            
        } else {
            $template->assign_block_vars("error", array('ERROR' => 'Identifiant / Mot de passe manquants !'));
        }
}

$template->assign_var('TITLE', 'Mutualisation Projet');
$template->assign_var('CSS_PAGE', './style/css/index.css');

$template->pparse('header');
$template->pparse('body');
$template->pparse('footer');

// appel du footer
require_once('./include/footer.php');

?>
